package threshold;

import java.util.Collections;
import java.util.List;

public class PositiveRatioNDCRThresholdFinder extends MaxNDCRThresholdFinder {

	private double ratio;
	
	@Override
	public List<String> initialize(List<String> args) {
		ratio = Double.parseDouble(args.get(0));
		return args.subList(1, args.size());
	}
	
	@Override
	public double find(List<Integer> label, List<Double> predicted) {
		List<Pair> pairList = getPairs(label, predicted);
		Collections.sort(pairList, comp);
		
		int positive = 0;
		for(int l : label) {
			if(l == 1) {
				positive ++;
			}
		}
		
		int mininum = (int)(ratio * positive);
		mininum = Math.min(mininum, pairList.size());
		
		Pair pair = pairList.get(mininum);

		System.out.println("minimum = " + mininum);
		
		return pair.logProb;
	}
}
